From 696b9a5df7fc89bf007a11c7f8b6a6a913229feb Mon Sep 17 00:00:00 2001 From: Daniel Boles Date: Fri, 25 Aug 2017 21:00:51 +0100 Subject: [PATCH] ComboBox: Use iter before popdown() may invalidate Bad actors, such as our very own FileChooserButton, may connect to the :popped-up property and alter the model as the menu becomes in/visible. We were getting an iter to the model while popped-up, then doing popdown(), then using the iter, which may have just been invalidated by the errant notify::popped-up handler. If so, we quickly crash fatally. This is clearly bonkers, but until such patterns are removed, we have to work around them. So, set_active() from the clicked item while it is known to be valid, by moving the call to set_active() before popdown(). While here, change set_active_iter(iter) to set_active_internal(path) to avoid pointlessly going through the iter to get the path we already have https://bugzilla.gnome.org/show_bug.cgi?id=729651 --- gtk/gtkcombobox.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c index a661c6974d..1bac65977a 100644 --- a/gtk/gtkcombobox.c +++ b/gtk/gtkcombobox.c @@ -3235,13 +3235,17 @@ gtk_combo_box_list_button_released (GtkWidget *widget, return TRUE; /* clicked outside window? */ gtk_tree_model_get_iter (priv->model, &iter, path); + + /* Use iter before popdown, as mis-users like GtkFileChooserButton alter the + * model during notify::popped-up, which means the iterator becomes invalid. + */ + if (tree_column_row_is_sensitive (combo_box, &iter)) + gtk_combo_box_set_active_internal (combo_box, path); + gtk_tree_path_free (path); gtk_combo_box_popdown (combo_box); - if (tree_column_row_is_sensitive (combo_box, &iter)) - gtk_combo_box_set_active_iter (combo_box, &iter); - return TRUE; } -- 2.30.2